package com.cskaoyan.service;

import com.cskaoyan.bean.FootPrint;
import com.cskaoyan.bean.FootPrintExample;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.mapper.FootPrintMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 杨杰
 * @version V1.0
 * @Package com.cskaoyan.service
 * @date 2020/12/5 20:11
 * @Copyright © 暂时还没有
 */
@Service
public class AdminFootprintServiceImp implements AdminFootprintService{
    @Autowired
    FootPrintMapper footPrintMapper;
    @Override
    public ListData<FootPrint> adminFootprintList
            (Integer page, Integer limit, String sort, String order, Integer userId, Integer goodsId) {

        PageHelper.startPage(page,limit);
        FootPrintExample footPrintExample = new FootPrintExample();
        footPrintExample.setOrderByClause(sort + " " +order);
        FootPrintExample.Criteria criteria = footPrintExample.createCriteria();
        if (userId != null){
            criteria.andUserIdEqualTo(userId);
        }
        if (goodsId != null){
            criteria.andGoodsIdEqualTo(goodsId);
        }

        List<FootPrint> footPrints = footPrintMapper.selectByExample(footPrintExample);

        ListData<FootPrint> listData = new ListData<>();
        listData.setItems(footPrints);
        long total = new PageInfo<>(footPrints).getTotal();
        listData.setTotal((int)total);

        return listData;
    }
}
